{% from 'include/input_macros.html' import input, select %}
{% for s in services %}
{% if s.0 == 'roxy-wi-checker' %}
    {% if s.3 != '* is not installed' and s.3 != '' %}
    <table id="checker_table" class="overview">
        <caption><h3>Add Telegram channel</h3></caption>
        <tr class="overviewHead" style="width: 50%;">
            <td class="padding10 first-collumn" style="width: 25%;">
                <span title="Token that has given @father_bot">Token</span>
            </td>
            <td style="width: 20%;">Channel name</td>
            {% if page != "servers.py" %}
            <td style="width: 25%;">Group</td>
            {% endif %}
            <td style="width: 100%;"></td>
            <td></td>
            <td><span onclick="loadchecker()" class="service-reload" title="Reload Telegram channels"></span></td>
        </tr>
        {% for telegram in telegrams %}
        <tr id="telegram-table-{{telegram.id}}" class="{{ loop.cycle('odd', 'even') }}">
            <td class="padding10 first-collumn">
                {% set id = 'telegram-token-' + telegram.id|string() %}
                {{ input(id, value=telegram.token, size='30') }}
            </td>
            <td>
                {% set id = 'telegram-chanel-' + telegram.id|string() %}
                {{ input(id, value=telegram.chanel_name, size='30') }}
            </td>
            {% if page != "servers.py" %}
            <td>
                <select id="telegramgroup-{{telegram.id}}" name="telegramgroup-{{telegram.id}}">
                    <option disabled selected>Choose group</option>
                    {% for group in groups %}
                    {% if telegram.groups|string() == group.group_id|string() %}
                    <option value="{{ group.group_id }}" selected>{{ group.name }}</option>
                    {% else %}
                    <option value="{{ group.group_id }}">{{ group.name }}</option>
                    {% endif %}
                    {% endfor %}
                </select>
            </td>
            {% endif %}
            <td>
                <button title="Send test message" onclick="checkTelegram({{telegram.id}})">Test</button>
            </td>
            <td>
                <a class="add" onclick="cloneTelegram({{telegram.id}})" id="clone-{{telegram.id}}" title="Clone {{telegram.chanel_name}}" style="cursor: pointer;"></a>
            </td>
            <td>
                <a class="delete" onclick="confirmDeleteTelegram({{telegram.id}})" title="Delete channel {{telegram.chanel_name}}" style="cursor: pointer;"></a>
            </td>
        </tr>
        {% endfor %}
    </table>
    <br /><span class="add-button" title="Add telegram channel" id="add-telegram-button">+ Add</span>
    <br /><br />
    <table id="checker_slack_table" class="overview">
        <caption><h3>Add Slack channel</h3></caption>
        <tr class="overviewHead" style="width: 50%;">
            <td class="padding10 first-collumn" style="width: 25%;">
                <span title="Token that has given with APP registration">Token</span>
            </td>
            <td style="width: 20%;">Channel name</td>
            {% if page != "servers.py" %}
            <td style="width: 25%;">Group</td>
            {% endif %}
            <td style="width: 100%;"></td>
            <td></td>
            <td><span onclick="loadchecker()" class="service-reload" title="Reload Slack channels"></span></td>
        </tr>
        {% for slack in slacks %}
        <tr id="slack-table-{{slack.id}}" class="{{ loop.cycle('odd', 'even') }}">
            <td class="padding10 first-collumn">
                {% set id = 'slack-token-' + slack.id|string() %}
                {{ input(id, value=slack.token, size='30') }}
            </td>
            <td>
                {% set id = 'slack-chanel-' + slack.id|string() %}
                {{ input(id, value=slack.chanel_name, size='30') }}
            </td>
            {% if page != "servers.py" %}
            <td>
                <select id="slackgroup-{{slack.id}}" name="slackgroup-{{slack.id}}">
                    <option disabled selected>Choose group</option>
                    {% for group in groups %}
                    {% if slack.groups|string() == group.group_id|string() %}
                    <option value="{{ group.group_id }}" selected>{{ group.name }}</option>
                    {% else %}
                    <option value="{{ group.group_id }}">{{ group.name }}</option>
                    {% endif %}
                    {% endfor %}
                </select>
            </td>
            {% endif %}
            <td>
                <button title="Send test message" onclick="checkSlack({{slack.id}})">Test</button>
            </td>
            <td>
                <a class="add" onclick="cloneSlack({{slack.id}})" id="clone-{{slack.id}}" title="Clone {{slack.chanel_name}}" style="cursor: pointer;"></a>
            </td>
            <td>
                <a class="delete" onclick="confirmDeleteSlack({{slack.id}})" title="Delete channel {{slack.chanel_name}}" style="cursor: pointer;"></a>
            </td>
        </tr>
        {% endfor %}
    </table>
    <br /><span class="add-button" title="Add Slack channel" id="add-slack-button">+ Add</span>
    <br /><br />
    <div id="ajax-telegram"></div>
    <div class="add-note alert addName alert-info" style="width: inherit; margin-right: 15px;">
        You can read the description of all parameters <a href="https://roxy-wi.org/description.py?description=checker" title="Servers description" target="_blank">here</a>,
        How to create and use Telegram bot in this <a href="https://roxy-wi.org/howto.py?howto=checker" title="How to create Telegram bot and use it with Roxy-WI" target="_blank">article</a>,
        How to create and use Slack APP in this <a href="https://roxy-wi.org/howto.py?howto=slack" title="How to create Slack APP and use it with Roxy-WI" target="_blank">article</a>
    </div>
    {% else %}
        <div style="text-align: center;">
            <br />
            <h3>You have not installed Backends checker
            Read <a href="https://roxy-wi.org/services.py?service=checker#installation" title="Checker installation" style="color: #5d9ceb;" target="_blank">hear</a>
            how to install Checker service</h3>
        </div>
    {% endif %}
{% endif %}
{% endfor %}
